<template>
  <div>
    <!--搜索查询-->
    <el-row>
      <!-- <el-col :span="">&nbsp;</el-col> -->
      <el-col :span="4"
        ><el-input
          v-model="searchForm.roleName"
          size="mini"
          clearable
          placeholder="请输入优惠券名称"
        ></el-input
      ></el-col>
      <el-col :span="2"
        ><el-button
          type="primary"
          size="mini"
          @click="search()"
          icon="el-icon-search"
          >搜索</el-button
        ></el-col
      >
      <el-col :span="2"
        ><el-button
          type="primary"
          size="mini"
          @click="flush()"
          icon="el-icon-refresh"
          >刷新</el-button
        ></el-col
      >
    </el-row>

    <el-row>
      <el-table :data="tableData" style="width: 100%">
          <el-table-column
          prop="couponName"
          width="150"
          label="优惠券名称"
        >
        </el-table-column>
          <el-table-column
          prop="memberName"
          width="150"
          label="用户名称"
        >
        </el-table-column>
        <el-table-column
          prop="getType"
          label="优惠券类型"
          :formatter="zhFormat"
          align="center"
          width="150"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          width="150"
          label="获取时间"
        >
        </el-table-column>
                <el-table-column
          prop="useStatus"
          label="使用状态"
          :formatter="AAFormat"
          align="center"
          width="150"
        >
        </el-table-column>
          <el-table-column
          prop="useTime"
          width="150"
          label="使用时间"
        >
        </el-table-column>
          <el-table-column
          prop="orderSn"
          width="150"
          label="订单编号"
        >
          </el-table-column>
        <!-- <el-table-column
          prop="delFlag"
          :formatter="delFormat"
          width="150"
          label="删除状态"
        > 
        </el-table-column>-->
      </el-table>
    </el-row>

    <el-row>
      <!--分页插件-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[2, 3, 5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [], //权限树数组对象
      defaultProps: {
        //父对象传值
        children: "children",
        label: "label",
      },
      nodeChecked: [], //勾选项目数组对象
      roleId: 0, //因为角色ID在不同的js方法种使用，定义为全局的
      tableData: [],
      title: "角色添加", //弹出对话框标题
      dialogFormVisible: false, //是否显示添加更新对话框  默认是不显示
      form: { roleName: "", remark: "", status: "0" }, //form表单对象
      currentPage: 1, //页码 第几页
      pageSize: 5, //每页显示数量
      total: 100, //总条数
      searchForm: { roleName: "" }, //搜索form表单
      dialogFormVisible: false, //是否显示对话框  默认是不显示
      form: {}, //form表单对象
      menuTreeVisible: false, //权限树是否显示
      formLabelWidth: "120px",
      rules: {
        roleName: [
          { required: true, message: "请输入角色名称", trigger: "blur" },
        ],
        remark: [
          { required: true, message: "请输入角色描述", trigger: "blur" },
          {
            min: 3,
            max: 50,
            message: "长度在 2 到 50 个字符",
            trigger: "blur",
          },
        ],
        status: [
          { required: true, message: "请选择角色状态", trigger: "change" },
        ],
      },
    };
  },
  created() {
    //初始化方法 类似于jquery  $({})
    this.loadData();
  },
  //所有函数
  methods: {
    //加载数据
    loadData() {
      var _this = this;
      //复制 $http官网代码
      // var token  = localStorage.getItem("token");
      _this.$http
        .post("/couponHistory/selectAllAndCouponAndOrderAndMember", {
          pageNo: this.currentPage,
          pageSize: this.pageSize,
          data: {
            orderSn: this.searchForm.roleName,
          },
        })
        .then(function (response) {
          if (response.data.code == 200) {
            _this.tableData = response.data.data.records;
            _this.total = response.data.data.total;
          }
        })
        .catch(function (error) {
          console.log(error);
          _this.$message.error("你错了。。。");
        });
    },
    zhFormat(row, column, cellValue, index) {
      var returnValue = "";
      if (cellValue == 0) {
        returnValue = "后台赠送";
      } else if (cellValue == 1) {
        returnValue = "主动获取";
      } 
      return returnValue;
    },
    AAFormat(row, column, cellValue, index) {
      var returnValue = "";
      if (cellValue == 0) {
        returnValue = "已使用";
      } else if (cellValue == 1) {
        returnValue = "未使用";
      } else if (cellValue == 2) {
        returnValue = "已过期";
      }
      return returnValue;
    },
    delFormat(row, column, cellValue, index) {
      //row当前行数据
      //column 列名称
      //cellValue 列的值
      //index 下标
      //alert(cellValue);
      return cellValue == 0 ? "存在" : "消失了";
    },
    //处理每页数量发生变化
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      //让每页数量发生变化
      this.pageSize = val;
      //重载数据
      this.loadData();
    },
    //处理当前页变化
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      //让每页数量发生变化
      this.currentPage = val;
      //重载数据
      this.loadData();
    },
    //查询
    search() {
      this.loadData();
    },
    //刷新
    flush() {
      location.reload();
    },
    //取消按钮
    dialogFormVisiblExit() {
      this.form = "";
      this.dialogFormVisibleAdd = false;
    },
  },
};
</script>
<style>
</style>
